﻿'Params
'artist (Required (unless mbid)] : The artist name
'album (Required (unless mbid)] : The album name
'mbid (Optional) : The musicbrainz id for the album
'autocorrect[0|1] (Optional) : Transform misspelled artist names into correct artist names, returning the correct version instead. The corrected artist name will be returned in the response.
'api_key (Required) : A Last.fm API key.

'Auth
' This service does not require authentication. 

Public Structure AlbumGetTopTagsResponse
    Dim tags() As Tag
End Structure

Public Class AlbumGetTopTags
	Inherits BaseRequest
	Dim artist As String
	Dim album As String
	Dim mbid As String
	Dim autocorrect As String

	Public xmlresponse As XDocument = Nothing

	Public Sub New(artist As String, album As String, mbid As String, autocorrect As String)
		Me.artist = artist
		Me.album = album
		Me.mbid = mbid
		Me.autocorrect = autocorrect

	End Sub

	Public Sub sendRequest()
		ClearMembers()

        AddMember("method", "album.getTopTags")
		AddMember("artist", artist, String.IsNullOrEmpty(mbid))
		AddMember("album", album, String.IsNullOrEmpty(mbid))
		AddMember("mbid", mbid, False)
		AddMember("autocorrect", autocorrect, False)

		AddMember("api_key", My.Settings.api_key, False)

        xmlresponse = sendGETResponse(False)
	End Sub

	Public Function getResponse() As AlbumGetTopTagsResponse
        Dim response As AlbumGetTopTagsResponse = Nothing
        Dim count As Integer
        Try
            count = xmlresponse.<lfm>.<toptags>.<tag>.Count()
        Catch ex As Exception
            Return response
        End Try
        If (count > 0) Then
            ReDim response.tags(count - 1)
            For i As Integer = 0 To count - 1
                response.tags(i) = New Tag(xmlresponse.<lfm>.<toptags>.<tag>(i))
            Next
        End If
        Return response
	End Function

End Class
